import {
  ApiTags,
  ApiOperation,
  ApiProperty,
  ApiBearerAuth,
  ApiCreatedResponse,
  ApiOkResponse,
  ApiNotFoundResponse,
  ApiForbiddenResponse,
  ApiBody,
  ApiQuery,
} from '@nestjs/swagger';
import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
  Query,
} from '@nestjs/common';
import { PermissionService } from './permission.service';
import { CreatePermissionDto } from './dto/create-permission.dto';
import { UpdatePermissionDto } from './dto/update-permission.dto';
import { Public } from '../common/isPublic';
import { QueryPermissionDto } from './dto/query-permission.dto';
@ApiTags('perm') // 用于指定控制器处理的API的标签
@Controller('perm')
@Public()
export class PermissionController {
  constructor(private readonly permissionService: PermissionService) {}

  @Post()
  @ApiOperation({ summary: '创建权限' }) // 用于指定操作的简短描述
  @ApiCreatedResponse({
    description: '权限创建成功',
    type: CreatePermissionDto,
  }) // 用于指定创建成功的响应
  @ApiBody({ type: CreatePermissionDto }) // 用于指定请求体的类型
  create(@Body() createPermissionDto: CreatePermissionDto) {
    return this.permissionService.create(createPermissionDto);
  }

  @Get()
  @ApiOperation({ summary: '获取所有权限' })
  @ApiOkResponse({
    description: '获取权限列表成功',
    type: [QueryPermissionDto],
  })
  findAll(@Query() query: QueryPermissionDto) {
    return this.permissionService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取权限' })
  @ApiOkResponse({ description: '权限信息', type: CreatePermissionDto })
  @ApiNotFoundResponse({ description: '权限不存在' })
  findOne(@Param('id') id: string) {
    return this.permissionService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新权限信息' })
  @ApiOkResponse({ description: '权限更新成功', type: CreatePermissionDto })
  @ApiNotFoundResponse({ description: '权限不存在' })
  update(
    @Param('id') id: string,
    @Body() updatePermissionDto: UpdatePermissionDto,
  ) {
    return this.permissionService.update(id, updatePermissionDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除权限' })
  @ApiOkResponse({ description: '权限删除成功' })
  @ApiNotFoundResponse({ description: '权限不存在' })
  remove(@Param('id') id: string) {
    return this.permissionService.remove(id);
  }
}
